package com.huatai.paas.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huatai.common.util.CollectionUtil;
import com.huatai.paas.dto.ItemModelMessage;
import com.huatai.paas.dto.UploadFileMessage;
import com.huatai.paas.dto.info.QueryFileListInfo;
import com.huatai.paas.dto.info.QueryModelManagementInfo;
import com.huatai.paas.mapper.UploadFileMessageMapper;
import com.huatai.paas.service.UploadFileMessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <b>UploadFileMessageServiceImpl</b>
 *
 * @description: UploadFileMessageServiceImpl <br>
 * @date: 2024/10/11 10:59 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class UploadFileMessageServiceImpl extends ServiceImpl<UploadFileMessageMapper, UploadFileMessage> implements UploadFileMessageService {
	private static final Logger logger = LoggerFactory.getLogger(UploadFileMessageServiceImpl.class);


	@Override
	public List<UploadFileMessage> queryFileMessage() {
		return baseMapper.queryFileMessage();
	}

	@Override
	public List<UploadFileMessage> queryFileMessageByFileId(List<ItemModelMessage> itemModelMessageList) {
		return baseMapper.queryFileMessageByFileId(itemModelMessageList);
	}

	@Override
	public IPage<QueryFileListInfo> queryFileList(Integer pageNum, Integer pageSize, String fileType) {
		Page<QueryModelManagementInfo> page = new Page<>(pageNum, pageSize);
		return baseMapper.queryFileList(page,fileType);
	}

	@Override
	public boolean deleteFileById(Long id) {
		int i = baseMapper.deleteById(id);
		if (i == 1){
			return true;
		}
		return false;
	}

	@Override
	public boolean checkFileData(String md5Data, String fileType) {
		QueryWrapper queryWrapper = new QueryWrapper();
		queryWrapper.eq("file_type",fileType);
		queryWrapper.eq("md5_data",md5Data);
		List<UploadFileMessage> fileMessageList = baseMapper.selectList(queryWrapper);
		if (CollectionUtil.isNotEmpty(fileMessageList)){
			return true;
		}
		return false;
	}
}
